package ink.carnation.imtalk.controller.email;

import ink.carnation.imtalk.annotation.IPLimit;
import ink.carnation.imtalk.annotation.Limiter;
import ink.carnation.imtalk.annotation.PassToken;
import ink.carnation.imtalk.model.IMResult;
import ink.carnation.imtalk.model.vo.EmailVO;
import ink.carnation.imtalk.service.EmailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Email;

/**
 * @author: flbu920
 * @date 2020/9/24
 */
@RestController
@Api("发送邮件")
@RequestMapping("/emails")
@Validated
public class EmailController {
    @Autowired
    private EmailService emailService;

    @PostMapping("/send")
    @ApiOperation("发送邮件，传入email地址")
    @PassToken
    @IPLimit(count = 1,time = 60)
    @Limiter(LimitNum = 10)
    public IMResult sendEmail( @Email(message = "非邮箱格式")  @RequestParam("email") String email) {
        String message = emailService.sendEmail(email);
        return IMResult.success(new EmailVO(email, message));
    }
}
